home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / LProgressIndicator & Friends / LAnimateCursor / LAnimateCursor.cp < prev    next >
Encoding:
Text File  |  1996-04-20  |  2.0 KB  |  114 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        LAnimateCursor.cp
  3.     
  4.     Contains:    Cursor spinning routines.
  5.  
  6.     Copyright:    ©1995 Chris K. Thomas.  All Rights Reserved.
  7.     
  8.     Version:    2.1
  9. */
  10.  
  11. #include "LAnimateCursor.h"
  12.  
  13. //
  14. // ————• construct ———————————————————————————————————————————————————
  15. //
  16.  
  17. LAnimateCursor::LAnimateCursor(const short inStartID, const short inNumCursors)
  18.     :LProgressIndicator(task_Indeterminate, 0, inNumCursors, 0),
  19.      LCursor(0),
  20.      mYCursors(sizeof(LCursor *))
  21. {
  22.     //
  23.     // • init state
  24.     //
  25.  
  26.     mCursorIterator = 1;
  27.     mCursorHandle = NULL;
  28.     Lock();
  29.     
  30.     //
  31.     // • grab cursors and stuff into our array
  32.     //
  33.     LCursor    *ourCursor;
  34.     
  35.     // resize the handle just once, thanks
  36.     mYCursors.AdjustAllocation(inNumCursors);
  37.     
  38.     for(short i = inStartID; i < (inStartID + inNumCursors); i++)
  39.     {
  40.         ourCursor = new LCursor(i);//(CursHandle)GetResource('CURS', i);
  41.         ThrowIfNULL_(ourCursor);
  42.         
  43.         mYCursors.InsertItemsAt(1, mYCursors.GetCount() + 1, &ourCursor);
  44.     }
  45.     
  46.     //
  47.     // setup tick counter
  48.     //
  49.     mLastTicks = TickCount();
  50. }
  51.  
  52. LAnimateCursor::~LAnimateCursor()
  53. {
  54.     Unlock();
  55.     InitCursor();    // ••• FIXME -- restore old cursor
  56.     
  57.     LCursor        *ourCurs;
  58.     UInt32        curCursCount;
  59.     
  60.     curCursCount = mYCursors.GetCount();
  61.     
  62.     //
  63.     // release the last cursor in the array
  64.     // until no more items exist
  65.     //
  66.     while(curCursCount > 0)
  67.     {
  68.         if(mYCursors.FetchItemAt(curCursCount, &ourCurs))
  69.         {
  70.             delete ourCurs;
  71.         }
  72.         --curCursCount;
  73.     }
  74. }
  75.  
  76.  
  77. // —————————• Implementation———————————————————————————————————————————————
  78.  
  79. //
  80. // • rotate the cursor
  81. //
  82. void LAnimateCursor::Set()
  83. {
  84.     //
  85.     // prevent cursor flash and poor performance
  86.     // by ensuring a threshold number of ticks have
  87.     // passed since last spin
  88.     //
  89.     
  90.     if((TickCount() - mLastTicks) > kMinSpinTicks)
  91.     {
  92.         LCursor *ourCursor;
  93.         
  94.         //
  95.         // rotate to the next cursor
  96.         //
  97.         mCursorIterator++;
  98.         
  99.         if(mCursorIterator > mYCursors.GetCount())
  100.             mCursorIterator = 1;
  101.         
  102.         if(mYCursors.FetchItemAt(mCursorIterator, &ourCursor))
  103.         {
  104.             ourCursor->Set();
  105.         }
  106.         else
  107.         {
  108.             SignalPStr_("\pCouldn't find a cursor!");
  109.         }
  110.         
  111.         mLastTicks = TickCount();
  112.     }
  113. }
  114.